package com.ruoyi.web.controller.food;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.food.domain.WarehouseEntry;
import com.ruoyi.food.service.IWarehouseEntryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 粮食入库Controller
 * 
 * @author ruoyi
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/food/entry")
public class WarehouseEntryController extends BaseController
{
    @Autowired
    private IWarehouseEntryService warehouseEntryService;

    /**
     * 查询粮食入库列表
     */
    @PreAuthorize("@ss.hasPermi('food:entry:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseEntry warehouseEntry)
    {
        startPage();
        List<WarehouseEntry> list = warehouseEntryService.selectWarehouseEntryList(warehouseEntry);
        return getDataTable(list);
    }

    /**
     * 导出粮食入库列表
     */
    @PreAuthorize("@ss.hasPermi('food:entry:export')")
    @Log(title = "粮食入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseEntry warehouseEntry)
    {
        List<WarehouseEntry> list = warehouseEntryService.selectWarehouseEntryList(warehouseEntry);
        ExcelUtil<WarehouseEntry> util = new ExcelUtil<WarehouseEntry>(WarehouseEntry.class);
        util.exportExcel(response, list, "粮食入库数据");
    }

    /**
     * 获取粮食入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('food:entry:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(warehouseEntryService.selectWarehouseEntryById(id));
    }

    /**
     * 新增粮食入库
     */
    @PreAuthorize("@ss.hasPermi('food:entry:add')")
    @Log(title = "粮食入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseEntry warehouseEntry)
    {
        return toAjax(warehouseEntryService.insertWarehouseEntry(warehouseEntry));
    }

    /**
     * 修改粮食入库
     */
    @PreAuthorize("@ss.hasPermi('food:entry:edit')")
    @Log(title = "粮食入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseEntry warehouseEntry)
    {
        return toAjax(warehouseEntryService.updateWarehouseEntry(warehouseEntry));
    }

    /**
     * 删除粮食入库
     */
    @PreAuthorize("@ss.hasPermi('food:entry:remove')")
    @Log(title = "粮食入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(warehouseEntryService.deleteWarehouseEntryByIds(ids));
    }
}
